package com.beerandjesus.sportofkings.handicapper.strategy.brisnet.singlefile;

import com.beerandjesus.sportofkings.handicapper.model.RaceAnalysisResultVOImpl;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.Horse;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.Race;
import com.beerandjesus.sportofkings.handicapper.strategy.KeyTrainerStatisticsResolver;
import com.beerandjesus.sportofkings.handicapper.strategy.RacingCalculator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class AbstractRaceAnalysisStrategy {

    private RacingCalculator calc = new RacingCalculator();
    private FastWorkoutsResolver fastWorkoutsResolver = new FastWorkoutsResolver();
    private final MorningLineOddsResolver morningLineOddsResolver = new MorningLineOddsResolver();
    @Autowired
    private KeyTrainerStatisticsResolver keyTrainerStatisticsResolver;

    public AbstractRaceAnalysisStrategy() {
        super();
    }

    protected void setCommonFields(RaceAnalysisResultVOImpl vo, Race r, List<Horse> horses) {
        vo.setFieldCount(horses.size());
        vo.setPurse(r.getPurse());
        vo.setClaimingPrice(r.getClaimingPrice());
        vo.setRaceName(r.getRaceClassification());
        vo.setRaceType(r.getType());
        vo.setSpeedPar(r.getBrisSpeedPar());
        vo.setSurface(r.getSurface());
        vo.setTrackCode(r.getTrack());
        vo.setRaceDate(r.getDate());
        vo.setRaceNumber(r.getRaceNumber());
        vo.setPostTimes(r.getPostTimes());
        vo.setDistance(calc.distanceFromYards(r.getDistance()));
    }

    protected Integer getPostPosition(Horse h) {
        String postPosition = h.getProgramPostPosition();
        if (StringUtils.isEmpty(postPosition)) {
            postPosition = h.getPostPosition();
        }
        return new Integer(postPosition);
    }

    public MorningLineOddsResolver getMorningLineOddsResolver() {
        return morningLineOddsResolver;
    }

    public FastWorkoutsResolver getFastWorkoutsResolver() {
        return fastWorkoutsResolver;
    }

    public void setKeyTrainerStatisticsResolver(KeyTrainerStatisticsResolver keyTrainerStatisticsResolver) {
        this.keyTrainerStatisticsResolver = keyTrainerStatisticsResolver;
    }

    public KeyTrainerStatisticsResolver getKeyTrainerStatisticsResolver() {
        return keyTrainerStatisticsResolver;
    }
}